package com.zsinfo.guoss.supplier;

import android.app.Activity;
import android.app.Application;

import com.orhanobut.logger.Logger;

import java.util.ArrayList;
import java.util.List;

import cn.jpush.android.api.JPushInterface;

/**
 * Created by lixl on 2018/12/4.
 * <p>
 * desc:
 */
public class MyApplication extends Application {

    private static final String TAG = "JIGUANG-Example";

    public static MyApplication instance;//App对象的单例
    public static List<Activity> stackList=new ArrayList<>();
    @Override
    public void onCreate() {
        super.onCreate();

        Logger.d(TAG, "[ExampleApplication] onCreate");
        JPushInterface.setDebugMode(true); 	// 设置开启日志,发布时请关闭日志
        JPushInterface.init(this);     		// 初始化 JPush，
        // 登录成功之后，设置别名，
        // 退出登录，删除别名

        if (instance == null) {
            instance = this;
        }

    }

    /**
     * 添加
     * @param activity
     */
    public static void addToStackList(Activity activity){
        if (!stackList.contains(activity)){
            stackList.add(activity);
        }
    }

    /**
     * 移除指定的
     * @param activity
     */
    public static void removeFromStackList(Activity activity){
        if (!stackList.contains(activity)){
            stackList.remove(activity);
        }
    }

    /**
     * 关闭所有的Activity
     */
    public static void removeAll(){
        if (stackList != null){
            for (int i = 0; i < stackList.size(); i ++) {
                stackList.get(i).finish();
            }
            stackList.clear();
        }
    }
}
